package com.fjwt.gz.task.sysExport;

import com.fjwt.gz.core.constants.Constants;
import com.fjwt.gz.db.entity.SysExportTaskEntity;
import com.fjwt.gz.service.impl.SysExportTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 报表导出
 */
@Component
@Slf4j
public class SysExportTask {

    @Autowired
    private SysExportTaskService sysExportTaskService;

    @Scheduled(cron = "*/30 * * * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void SysExportList() {
        List<SysExportTaskEntity> list = sysExportTaskService.lambdaQuery()
                .eq(SysExportTaskEntity::getStatus, Constants.EXPORT_TASK_ENUM.STATUS.PENDING).list();
        for (SysExportTaskEntity sysExportTaskEntity : list){
            log.info("开始执行报表导出任务：{}", sysExportTaskEntity.getExportTaskId());
            sysExportTaskEntity.setStatus(Constants.EXPORT_TASK_ENUM.STATUS.PROCESSING);
            sysExportTaskService.updateById(sysExportTaskEntity);
            sysExportTaskService.receive(sysExportTaskEntity.getExportTaskId());
        }
    }
}
